package com.stars.home.vmodel

import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.stars.home.activity.*
import com.stars.home.update.bean.UpdateBean
import com.stars.home.utils.net.NetEngine
import com.tencent.mmkv.MMKV
import com.trailer.base.base.BRepository
import com.trailer.base.base.BViewModel
import com.trailer.base.utils.B
import com.trailer.base.utils.UiSwitch
import kotlinx.coroutines.launch


class SettingVModel(application: Application) : BViewModel<BRepository>(application) {

    var bean= MutableLiveData<UpdateBean>()
    var phone=MutableLiveData<String>()

    fun toRealName(){
        //实名认证

        UiSwitch.single(repository().context, RealNameActivity::class.java)

    }

    //更换手机号
    fun toChangePhone(){
        UiSwitch.single(repository().context, ChangePhoneActivity::class.java)

    }

    //注销手机号
//    fun toDestruction(){
//
//        UiSwitch.single(repository().context, DestructionActivity::class.java)
//
//    }

    fun toDestruct(){
        viewModelScope.launch {
            var it=repository().lreq { NetEngine.service.memberLogout() }
            if(it.ok(true)){
                MMKV.defaultMMKV().putString("token", "")
                UiSwitch.single_new_task_with_clear_task(repository().context, OneLoginActivity::class.java)
            }
        }
    }

    fun toAgreement(type:Int){
        if(type==1){//服务协议

            UiSwitch.bundle(repository().context,
                    ArticleDetailActivity::class.java, B().putString("type","1").ok())
        }else{//隐私协议
            UiSwitch.bundle(repository().context,
                    ArticleDetailActivity::class.java, B().putString("type","2").ok())

        }

    }




    fun getAppConfig(){
        viewModelScope.launch {
            var it=repository().lreq { NetEngine.service.payOrder("1") }
            if(it.ok()){
                bean.value=it.data
            }

        }
    }

    fun getRate(){
        viewModelScope.launch {
            var it=repository().lreq { NetEngine.service.configList() }
            if(it.ok()){
                phone.value=it.data?.platformPhone
            }
        }
    }


}



